
package com.pojoin.cms.util.pager;

import java.util.List;

/**
 * @author haines
 */
public class Pager {
	private final int PAGE_SIZE=10;
	private final int PAGE_NO=1;
	/**
	 * startRow 当前页所显示的第一条数据在数据库中的行数
	 */
	private Integer startRow;
	/**
	 * 每页显示的数据的条数
	 */
	private int pageSize;
	/**
	 * 当前页数	
	 */
	private int pageNo;
	/**
	 * 总的数据条数	
	 */
	private int resultCount;
	/**
	 * 总页数
	 */
	private int pageCount;
	/**
	 * 下一页
	 */
	private int pageNext;
	/**
	 * 上一页
	 */
	private int pagePrevious;
	/**
	 * 是否有上一页
	 */
	@SuppressWarnings("unused")
	private boolean isPagePrevious;
	/**
	 * 是否有下一页码
	 */
	@SuppressWarnings("unused")
	private boolean isPagerNext;
	/**
	 * 当前页所有的记录
	 */

	@SuppressWarnings("rawtypes")
	private List list;
	
	private boolean doPager = true;
	
	/**
	 * 用户请求的url
	 */
	private String action;
	
	public String getAction() {
		return action;
	}
	public void setAction(String action) {
		this.action = action;
	}
	public boolean isDoPager() {
		return doPager;
	}
	public void setDoPager(boolean doPager) {
		this.doPager = doPager;
	}

	@SuppressWarnings("rawtypes")
	public List getList() {
		return list;
	}
	
	@SuppressWarnings("rawtypes")
	public void setList(List list) {
		this.list = list;
	}
	public Pager(){
		this.pageNo=PAGE_NO;
		this.pageSize=PAGE_SIZE;
	}
	public Pager(int pageNo,int pageSize){
		this.pageNo=pageNo;
		this.pageSize=pageSize;
	}
	public int getStartRow(){
		startRow=pageSize*(pageNo-1)+1;
		return startRow;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {	
		this.pageNo = pageNo;
	}
	public int getResultCount() {
		return resultCount;
	}
	public void setResultCount(int resultCount) {
		this.resultCount = resultCount;
		if(resultCount%pageSize==0){
			pageCount=resultCount/pageSize;
		}
		else{
			pageCount=resultCount/pageSize+1;
		}
	}
	
	public int getPageCount() {
		if(resultCount%pageSize==0){
			pageCount=resultCount/pageSize;
		}
		else{
			pageCount=resultCount/pageSize+1;
		}
		return pageCount;
	}
	
	public int getPageNext() {
		if(pageNo<pageCount){
			pageNext=pageNo+1;
		}
		else{
			pageNext=pageNo;
		}
		return pageNext;
	}

	public int getPagePrevious() {
		if(pageNo>1){
			pagePrevious=pageNo-1;
		}
		else{
			return pagePrevious=pageNo;
		}
		return pagePrevious;
	}

	public boolean getIsPageNext() {
		if(pageNo>=pageCount){
			return false;
		}
		else{
			return true;
		}
	}
	public boolean getIsPagePrevious() {
		if(pageNo<=1){
			return false;
		}
		else{
			return true;
		}
	}
}

